<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use User\Api\UserApi;



/**
 * 商品分类页
 * 
 */
class GoodsClassifyController extends HomeController 
{
	/* 商品分类页 */
	public function classify()
	{


		if (IS_GET) {
			$goods = D('goods');
			$data = $goods->showclassify();

			
			
			$k = 0;
			foreach ($data['bigimg'] as $key => &$value) {
				foreach ($value as $ke => &$val) {
					$val['path'] = ltrim(  $val['path'] , '.');
				}

			}

			// 压图片
			$res = [];
			$g = [];
			$i = 0;
			foreach ($data['bigimg'] as $key1 => &$value1) {
				// echo $value1[0]['goods_id'];
				$map['goods_id'] = ['eq' , $value1[0]['goods_id']];
				$goods = M('goods');
				$res = $goods->field('name , goods_id')->where($map)->select();


				$mvp['name'] = [ 'eq' , $res[0]['name'] ];
				// print_r($mvp);
				$g = $goods->where(" name like '%{$res[0]['name']}%'")->select();

				if (count($g) >= 2) {
					foreach ($g as $gkey => $gvalue) {

						if ($gvalue['goods_id'] != $value1[0]['goods_id']) {
							$mm['goods_id'] = ['eq' , $gvalue['goods_id']];

							$imgdb = M('image');
							$imghaha = $imgdb->where($mm)->select();

							$a = array_merge($value1 , $imghaha);
							$value1 = $a;

						}

					}
				}
				
				
				$i++;
			}


			$this->assign('bigimg' , $data['bigimg']);
			$this->assign('goods' , $data['goods']);
			$this->assign('imglist' , $data['img']);
			$this->assign('show' , $data['show']);
			$this->assign('count' , $data['count']);
			$this->assign('pagenum' , $data['pagenum']);
			$this->assign('hot' , $data['hot']);
			$this->assign('bread' , $data['bread']);


			$this->assign('id' , $data['kkk']);
			$this->assign('ss' , $data['ss']);
			$this->assign( $data);

			$this->assign('test','123');

			$this->display();
			

		}

		// ajax分页
		if (IS_POST) {
			$this->refer();			
			
		}
		
	}

	public function refer(){
		$goods = D('goods');
		$data = $goods->showclassify();
		// echo '<pre>';
		// 	print_r($data['ids']);
		// echo '<pre>';
		// // exit;
		$this->assign('goods' , $data['goods']);
		$this->assign('imglist' , $data['img']);
		$this->assign('show' , $data['show']);
		$this->assign('count' , $data['count']);
		$this->assign('pagenum' , $data['pagenum']);
		$this->assign('hot' , $data['hot']);


		$this->assign('id' , $data['kkk']);
		$this->assign( $data);

		$this->assign('test','123');

		$this->display();
	}

	public function addcart(){

		$goods = D('goods');

		$data = $goods->showclassify();

	}

	// 访问量
	public function action(){
		$report = new \Home\Model\GoodsModel();
		$res = $report->addreport();
	}

}

